
<template>
     <h2>登录页面</h2>
     <table>
         <tr>
             <td>用户名</td>
             <td><input type="text" v-model="info.username"></td>
         </tr>
         <tr>
             <td>密码</td>
             <td><input type="password" v-model="info.password"></td>
         </tr>
         <tr>
            <td colspan="2">
            <input type="button" value="登录" @click="SaveData"/>
            <RouterLink to="/Register">无法登录!注册账号</RouterLink>
            </td>
         </tr>
     </table>
</template>


<script setup lang="ts">
   import {ref} from 'vue'
   import axios from 'axios'
   
   const info = ref({
       username:'',
       password:''
   })
   
   const SaveData = ()=>{
       if(info.value.username=='')
       {
           alert('用户名不能为空');
           return;
       }
       if(info.value.password=='')
       {
           alert('密码不能为空');
           return;
       }
       //发送请求
       axios({
           url:"https://localhost:44346/api/Users/UserLogin",
           method:"get",
           params:{
               Uname:info.value.username,
               Upwd:info.value.password
           }
       }).then(function(res){
            if(res.data==111)
            {
                alert('用户名不存在!');
                
            }else if(res.data==222){
                alert('密码错误!');
            }else {
                alert('登录成功!');
            }
       }).catch(function(err){
           console.log(err);
       }).finally(function(){
           console.log('请求结束!');
       })
   }


</script>